import { useUserStore,useFormStore } from '@/common/stores'
/**
 * 是否登录
 */
function isLogin(){
	const token = uni.getStorageSync('token') || ''
	return !uni.$uv.test.empty(token)
}
/**
 * 获取登录token
 */
function getToken() {
	return uni.getStorageSync('token') || ''
}
/**
 * 存储token
 * @param {Object} token
 */
function saveToken(token){
	uni.setStorageSync('token',token)
}
/**
 * 退出登录
 * @param { string } skip 是否需要跳转到登录页面
 */
function logout(skip = true){
	uni.removeStorageSync('token')
	const userStore = useUserStore()
	const formStore = useFormStore()
	userStore.$reset()
	formStore.$reset()
	if(skip){
		uni.reLaunch({
			url:'/pages/login/login'
		})
	}
}
/**
 * 获取认证状态
 * 认证状态 00:已认证 01:未认证 02:认证中 03:认证失败
 */
function getAuthStatus() {
	const userStore = useUserStore()
	return userStore.user.authStatus
}
export default {
	isLogin,
	logout,
	getToken,
	getAuthStatus,
	saveToken
}